package com.gwtjs.icustom.controller;

import com.gwtjs.icustom.pojo.User;
import com.gwtjs.icustom.utils.ImportExcelUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UploadController {

    @Resource
    ImportExcelUtils excelUtils;

    @PostMapping("/upload")
    public Map<String,String> upload(MultipartFile excelFile) throws Exception{
        Map<String,String> map = new HashMap<>();
        if (excelFile.isEmpty()){
            map.put("mag","文件夹为空，重新上传");
        }else {
            String fileName = excelFile.getOriginalFilename();
            InputStream is = excelFile.getInputStream();
            List<User> userList = excelUtils.upload(fileName, is);
            System.out.println(userList.toString());
            /**
             * if (userService.importUserInfo(fileName,is)){
             *                 map.put("msg","数据添加成功");
             *             }else {
             *                 map.put("msg","数据添加失败，请重新添加");
             *             }
             */

        }

        return map;
    }
}

